(** functions to print out the AST *)

open Symbols;;


let rec print_indent indent = if indent > 0 then (print_string "   "; print_indent (indent -1))

let rec print_stmt indent s =
    print_indent indent;
    match s with
    Assign (e1, e2) -> 
        print_endline "Assign";
        print_expr (indent +1) e1 ;
        print_expr (indent +1) e2
  | Stmt_list ss ->
        print_endline "Stmt_list";
        List.iter (print_stmt (indent +1)) ss
  | Apodef (id, s) ->
        print_endline "Apodef";
        print_indent (indent +1); print_endline id;
        print_indent (indent +1); print_endline s;
  | Funcdef (id, args, body) ->
        print_endline "Funcdef";
        print_indent (indent +1); print_endline id;
        print_indent (indent +1); List.iter (fun s -> print_string (s^", ")) args;
        List.iter (print_stmt (indent +1)) body
  | Classdef (id, args, body) ->
        print_endline "Classdef";
        print_indent (indent +1); print_endline id;
        print_indent (indent +1); print_expr (indent +1) args;
        List.iter (print_stmt (indent +1)) body
  | Expr_stmt e ->
        print_endline "Expr_stmt";
        print_expr (indent +1) e;
  | Pass -> print_endline "Pass"
  | Return e -> 
        print_endline "Return";
        print_expr (indent +1) e;
  | If_stmt (test, if_t, if_f) ->
        print_endline "If_stmt";
        print_expr (indent + 1) test;
        print_endline "If true";
        List.iter (print_stmt (indent +1)) if_t;
        print_endline "If false";
        List.iter (print_stmt (indent +1)) if_f

and print_expr indent e = print_indent indent;
    match e with
    Integer i -> print_endline ("Integer "^ string_of_int i)
  | String s -> print_endline ("String "^ s)
  | Ident s -> print_endline ("Ident "^ s)
  | Call (id, es) ->
        print_endline ("Call ");
        print_expr (indent + 1) id;
        List.iter (print_expr (indent +2)) es
  | Attr_ref (obj, attr) ->
        print_endline ("Attr_ref");
        print_expr(indent + 1) obj;
        print_endline attr
  | _ -> print_newline ()


and print_type indent e = print_indent indent; print_newline ()

;;
